define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service_abroad_apply/index' + location.search,
                    add_url: 'service_abroad_apply/add',
                    detail_url: 'service_order/index',
                    edit_url: 'service_abroad_apply/edit',
                    del_url: 'service_abroad_apply/del',
                    multi_url: 'service_abroad_apply/multi',
                    import_url: 'service_abroad_apply/import',
                    table: 'service_abroad_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('订单编号'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('咨询中'), "1":__('已成交'), "2":__('已结束')}, formatter: Table.api.formatter.status},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'sex', title: __('Sex')},
                        {field: 'birthday', title: __('Birthday'), operate: 'LIKE'},
                        {field: 'identity_name', title: __('Identity_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'identity.name', title: __('Identity.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type.name', title: __('Type.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'education.name', title: __('Education.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'service.service_name', title: __('Service.service_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [{
                            name: 'detail',
                            title:__('订单信息'),
                            text: '订单',
                            classname: 'btn btn-xs btn-success btn-dialog',
                            url: "service_order/index?ids={order_id}",
                          }],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
